<#--
    This file should be located in the same package as the entity classes.
    - List of variables:
        - PackageDirectory
        - Package: the package name of entity classes.
        - PersistenceUnitName: The same as the one defined in the
                persistence.xml file.
-->
<@pp.dropOutputFile />
<@pp.changeOutputFile name="${PackageDirectory}"+"/DatabaseEntityManager.java" />

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ${Package};

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author selkhateeb
 */
public class DatabaseEntityManager
{
    private static String persistenceUnitName = "${PersistenceUnitName}";
    private static String schemaPersistenceUnitName = "Schema-${PersistenceUnitName}";

    public static EntityManager getEntityManager()
    {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnitName);
        return emf.createEntityManager();
    }
    public static EntityManager getSchemaEntityManager()
    {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(schemaPersistenceUnitName);
        return emf.createEntityManager();
    }
}
